﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace WpfApp_Property
{
    public class PassworldHelper
    {

        public static string GetCPassword(DependencyObject obj)
        {
            return (string)obj.GetValue(CPasswordProperty);
        }

        public static void SetCPassword(DependencyObject obj, string value)
        {
            obj.SetValue(CPasswordProperty, value);
        }

        // Using a DependencyProperty as the backing store for CPassword.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty CPasswordProperty =
            DependencyProperty.RegisterAttached(
                "CPassword",
                typeof(string),
                typeof(PassworldHelper),
                new PropertyMetadata("12121211", new PropertyChangedCallback(CPasswordPropertyChanged)));



        public static void CPasswordPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
        {
            if (e.NewValue != null)
            {
                MessageBox.Show($"绑定的密码发生了变化：{e.NewValue.ToString()}");
                if (obj is PasswordBox)
                {
                    (obj as PasswordBox)!.Password = e.NewValue.ToString();
                }
            }
               
        }


    }
}
